<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit %>
<!--#include file="includes/cb_adovbs_sys.inc"-->
<!--#include file="includes/header_sys.asp"-->
<!--#include file="includes/authority_sys.asp" -->
<!--#include file="includes/generally_sys.asp"-->
<!--#include file="includes/translate.asp"-->
<!--#include file="includes/email_config_.asp"-->
<!--#include file="includes/save_new_password.asp"-->
<!--#include file="includes/email_check.asp"-->

<%
On Error Resume Next
'Codepage einstellen
Session.CodePage = 65001'Unicode, 8-bit encoding
Response.CharSet = "utf-8"
Dim  objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.open strComplete_sys


If Request("action") = "setInquiry" Then
	
    If CStr(Session("ses_iu")) <> "" And CStr(Session("ses_iu")) <> "0" Then
        Dim rst1, i_count, sql1, inquiry1, user_id1
        i_count = fc_i_mk_user_pw_inquiry(CStr(Session("ses_iu")))
        Set rst1 = Server.CreateObject("ADODB.Recordset")
        sql1 = "SELECT lng_k_email_inquiry, str_User_id FROM tbl_0903_pw_inquiry " &_
		        "WHERE lng_fk_User_ID = '" & CStr(Session("ses_iu")) & "' " &_
		        "AND str_temp_pw IS NULL " &_
		        "ORDER BY lng_k_email_inquiry DESC LIMIT 1"
		rst1.Open sql1, objConn
		If Not rst.EOF Then
	        inquiry1 = rst1.Fields("lng_k_email_inquiry")
	        user_id1 = rst1.Fields("str_User_id")
	    end if
	    rst1.Close
        Response.Write("{status: 'OK', msg: '', inquiry: '" & inquiry1 & "', user_id: '" & user_id1 & "', iu: '" & Session("ses_iu") & "', ig: '" & Session("ses_ig") & "'}")
    Else
        Response.Write("{status: 'OK', msg: '', inquiry: '0', user_id: '0', iu: '0', ig: '0'}")
    End If
Else

    Dim i_lng
    i_lng = Request("lng")
    If IsEmpty(i_lng) or IsNull(i_lng) or i_lng = 0 Then
        If IsEmpty(Session("ses_i_language")) Then
            i_lng = 1
        Else
            i_lng = Session("ses_i_language")
        End If
    end if
    Session("ses_i_language")=i_lng'0=keine auswahl 1=german 2=english



    Dim lng_id
    lng_id = i_lng


    Dim sql, resp, inquiry, pw, uid, save_result, rst, str_user_id, first_name, last_name, email, redirect_email, email_text
    Set rst = Server.CreateObject("ADODB.Recordset")

    sql = "SELECT email FROM tbl_0904_pw_email WHERE active = 1 LIMIT 1"
    rst.Open sql, objConn

    If Not rst.EOF Then
        redirect_email = rst.Fields("email")
    Else
        redirect_email = "s.egorov@conquest-us.com"
    end if
    rst.Close


    inquiry = Replace(Request("inquiry"), "'", "''")
    pw = Replace(Request("pw"), "'", "''")
    uid = Replace(Request("uid"), "'", "''")

    save_result = save_new_password (inquiry, uid, pw)


    If save_result = 1 Then

        sql = "SELECT a.*, b.str_User_First_Name, b.str_User_Last_Name " &_
              "FROM tbl_0903_pw_inquiry a " &_
              "LEFT JOIN tbl_0501_user b ON b.str_User_id = a.str_User_id " &_
              "WHERE a.lng_k_email_inquiry = '" & inquiry & "' " &_
              "AND a.str_User_id = '" & uid & "' " &_
              "LIMIT 1"
        rst.Open sql, objConn
        If Not rst.EOF Then
            str_user_id = rst.Fields("str_User_id")
            first_name = rst.Fields("str_User_First_Name")
            last_name = rst.Fields("str_User_Last_Name")
            If redirect_email = "user" Then
                email = rst.Fields("str_email")
            Else
                email = redirect_email
            End If

        end if
        email_text = fc_value_string(lng_id, "var_email_template_lost_pw_02")
        email_text = Replace(email_text, "[FirstName]", first_name)
        email_text = Replace(email_text, "[LastName]", last_name)
        email_text = Replace(email_text, "[existing ID]", str_user_id)
        email_text = Replace(email_text, "[existing password]", pw)
        call sendmail_now(email, "support@growmetry.com", fc_value_string(lng_id, "var_lost_pw_49"), email_text)
        resp = "{status: 'OK', msg: '"&Replace(fc_value_string(lng_id, "var_lost_pw_31"), "'", "\'")&"'}"
    Else
        resp = "{status: 'error', msg: 'Internal Error "&save_result&"'}"
    End If


    If Err.Number <> 0 Then
        resp = "{status: 'error', msg: '"&Err.Description&"'}"
        Err.Clear
    End If
    Response.Write(resp)
End If

%>